package com.jarvis.plugin.wxmock.interceptor;

import cn.hutool.log.Log;
import com.google.inject.Inject;
import com.jarvis.plugin.wxmock.config.Constants;
import com.jarvis.plugin.wxmock.config.WxmockProperty;
import java.lang.reflect.Method;
import net.bytebuddy.asm.Advice.Argument;
import net.bytebuddy.asm.Advice.OnMethodEnter;
import net.bytebuddy.asm.Advice.Origin;
import org.apache.http.HttpHost;

/**
 * @author xuxukang
 * @create 2020/5/9 5:57 下午
 */
public class HttpclientInterceptor {
	
	@Inject
	public static WxmockProperty wxmockProperty;
	
	@OnMethodEnter
	public static void enter(@Origin Method method,
			@Argument(value = 0, readOnly = false) HttpHost httphost) {
		Log.get().info("【httphost】{}", httphost);
		
		String hostName = httphost.getHostName();
		if (Constants.real_wx_server_hostname.contains(hostName)) {
			httphost = HttpHost.create(wxmockProperty.getServer());
		}
	}
}
